<template>
	<view></view>
</template>

<script>
	let that;
	export default {
		data(){
			return {
				formData:{
					price:'',
					commission_status: 1,
					max_deduction_price: 0
				}
			}
		},
		beforeCreate(){
			that = this;
		},
		async onLoad(opt){
			uni.showLoading({title:'加载中...'});
			
			let pid = opt.pid ?? 0;
			if( pid ){
				uni.setStorageSync('pid', pid);
			}
				
			let data = opt.data ?? '';
			if( !opt.data ){
				that.errorHandler('请求状态异常~')
				return ;
			}
			let str = atob(opt.data);
			let params = JSON.parse(str);

			if(typeof params !== 'object') {
				that.errorHandler('请求参数错误~')
				return ;
			}
			for(let key in params){
				if(typeof params[key] === 'boolean'){
					params[key] = params[key] ? 1 : 0;
				}
			}
			
			let res = await this.$http.request({
				url: this.$api.moreShop.creatCheckOrder,
				method: 'POST',
				data: {id: params.mch_id,...params}
			});
			if(res.code !== 0 ){
				that.errorHandler(res.msg);
				return ;
			}
			uni.redirectTo({
				url:'/mch/personalCentre/ercode/payPages/pay?id='+res.data.id
			})
		},
		methods:{
			errorHandler(content){
				uni.hideLoading();
				uni.showModal({
					title:'温馨提示',
					content,
					showCancel:false,
					success(res){
						if(res.confirm) that.navBack();
					}
				})
			}
		},
	}
</script>

<style>
</style>